<?php

namespace App\Http\Controllers\Api;

use App\Models\Fangattr;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use function foo\func;

class FangattrController extends Controller
{
    public function getattr(Request $request)
    {
        $fang_field = $request->get('field');
        $pid        = Fangattr::where('field_name', $fang_field)->value('id');
        $data       = Fangattr::where('pid', $pid)->get();
        return $data;
    }

    // 获取属性
    public function attr()
    {
        $p_info = Fangattr::where('pid', 0)->limit(5)->get()->toArray();
        $arr    = [];
        $haha   = [];
        foreach ($p_info as $item) {
            $arr['id']         = $item['id'];
            $arr['name']       = $item['name'];
            $arr['pic']        = $item['pic'];
            $arr['field_name'] = $item['field_name'];
            $arr['child']      = Fangattr::where('pid', $item['id'])->get();
            $haha[]            = $arr;
        }
        return $haha;
    }
}
